#!/usr/bin/env bash
set -eo pipefail

repository=$1
app=${1%.git}
sha=$2
username=$3
fingerprint=$4

curl \
  -X 'POST' --fail \
  -H 'Content-Type: application/json' \
  -H "X-Deis-Builder-Auth: {{ getv "/deis/controller/builderKey" }}" \
  -d "{\"receive_user\": \"$username\", \"receive_repo\": \"$app\", \"sha\": \"$sha\", \"fingerprint\": \"$fingerprint\", \"ssh_connection\": \"$SSH_CONNECTION\", \"ssh_original_command\": \"$SSH_ORIGINAL_COMMAND\"}" \
  --silent {{ getv "/deis/controller/protocol" }}://{{ getv "/deis/controller/host" }}:{{ getv "/deis/controller/port" }}/v1/hooks/push >/dev/null
